var app = getApp();

var pageData = {
    data: {
        Headertab: 0,
        goods_box:[],
        showResult: false, //搜索结果展示
        itemStyle: 1, //商品列表显示方式 单列显示 1  双列显示 2
        res_data:[], //储存数据
        tab: 9,
        direction: 0,
        prevPage: 0,
        pageData: {},
        itemsList: [],
        history: [],
        inputContent: '',
        filterParam: {
            form: 'goods',
            id:0,
            page: 1,
            page_size: 10,
            sort_key: '',
            sort_direction: '',
            is_integral: '',
            idx_arr: {
                idx: '',
                idx_value: ''
            },
            search_value: '',
            region_id: ''
        },
        animationData: {},
        filter: false,
        locationList: [],
        DataUrl:'',
        DataObject:{},
        SelectFlag:0, //选择 状态
        GoodsAllMoney:0,
        url:'',
        data:'',

    },
    onLoad: function (e) {

    },
    onShow: function () {  //生命周期函数--监听页面显示  每次跳转到此页面 就会调用
      this.data.url = app.globalData.HOST + app.APILIST.getmyorder;
      this.data.data = {
        "data": {
          "userid": [app.globalData.UserInfo.id],
          "limit": app.globalData.goods_limit,
          'status': 1,
        }
      }
      this.userShopping();
    },
    OrderNavigation(e){
      this.data.filterParam.page = 0;
      this.setData({
        pageData: []
      });
      this.setData({
        itemsList: []
      });
      switch (e.currentTarget.dataset.flag){
        case '待付款':
          this.setData({
            Headertab: 0
          });
          this.data.url = app.globalData.HOST + app.APILIST.getmyorder;
          this.data.data = {
            "data": {
              "userid": [app.globalData.UserInfo.id],
              "limit": app.globalData.goods_limit,
              'status':1,
            }
          };
          this.userShopping();
           break;
        case '待发货':
          this.setData({
            Headertab: 1
          });
          this.data.url = app.globalData.HOST + app.APILIST.getmyorder;
          this.data.data = {
            "data": {
              "userid": [app.globalData.UserInfo.id],
              "limit": app.globalData.goods_limit,
              'status': 2,
            }
          };
          this.userShopping();
           break;
        case '待收货':
          this.setData({
            Headertab: 2
          });
          this.data.url = app.globalData.HOST + app.APILIST.getmyorder;
          this.data.data = {
            "data": {
              "userid": [app.globalData.UserInfo.id],
              "limit": app.globalData.goods_limit,
              'status': 1,
              "express":'abc'
            }
          };
          this.userShopping();
           break;
      };
    },


    userShopping(){   //用户购物车

     
      app.WxRequest(this.data.url, this.data.data,1,
                (res)=>{
                  console.log(res)

            this.setData({
                pageData: res
            })
            this.setData({
                itemsList: res.data
            })
        },( ref )=>{
        });
    // }
    },

    getMoreItems: function (e) {  //下拉 事件
    // console.log(e)
        let curPage = e.target.dataset.curpage;
        if (curPage < this.data.pageData.last_page) {
            this.data.filterParam.page = this.data.filterParam.page + 1;
            this.setData({prevPage: curPage});
            app.WxRequest(this.data.url,this.data.data,this.data.filterParam.page,
                (res) =>{
                var list = [...this.data.itemsList,...res.data];
                this.data.res_data = list;
            this.setData({
                pageData: res
            })
            this.setData({
                itemsList: list
            })
        },( ref )=>{
                console.log(ref);
            });
        };
    },

  order_payment(e){
    app.globalData.OrderList = [e.currentTarget.dataset.orderval];
    app.turnToPage('/pages/page_order/page_order');
  },
    dataInitial: function () {
        app.pageDataInitial();
    },
    /**
 * 跳转到详情页
 */
    turnToDetail: function (e) {

      // let id = e.currentTarget.dataset.id;
      // app.turnToPage('/eCommerce/pages/goodsDetail/goodsDetail?goodsid=' + id);

    },
    onShareAppMessage: function (e) {
        return app.onPageShareAppMessage(e);
    },


};
Page(pageData);
